// <copyright file="DropDownButton.aspx.cs" company="YUIAsp.Net">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>raul popescu</author>
// <email>dev@yuiasp.net</email>
// <date>2009-01-30</date>
// <summary>YUIAsp.Net File</summary>

using System;
using System.Globalization;

namespace YUIAspNetDemo.Button
{
    public partial class DropDownButton : BaseDemoPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                SetButtonText(btnMnu, btnMnu.ButtonMenu.Items[0].Text);
                btnMnu.Value = btnMnu.ButtonMenu.Items[0].Value;

                hidMenu.Value = btnMnu.ButtonMenu.Items[0].Text + "|" + btnMnu.ButtonMenu.Items[0].Value;

                SetButtonText(btnSplit, btnSplit.ButtonMenu.Items[0].Text);
                btnSplit.Value = btnSplit.ButtonMenu.Items[0].Value;
                hidSplit.Value = btnSplit.ButtonMenu.Items[0].Text + "|" + btnSplit.ButtonMenu.Items[0].Value;
            }

            btnPB.Click += new EventHandler<YUIAspNet.ButtonEventArgs>(btnPB_Click);
        }

        private void SetButtonText(YUIAspNet.Button button, string text)
        {
            button.Text = string.Format(CultureInfo.InvariantCulture, "<div class='btnWidth'>{0}</div>", text);
        }

        void btnPB_Click(object sender, YUIAspNet.ButtonEventArgs e)
        {
            lbl.Text =
                string.Format(CultureInfo.InvariantCulture,
                    "Menu button: [Text:{0}; Value: {1}]<br />Split Button: [Text:{2}; Value: {3}]",
                    hidMenu.Value.Split('|')[0], hidMenu.Value.Split('|')[1],
                    hidSplit.Value.Split('|')[0], hidSplit.Value.Split('|')[1]);

            //restore text and value from hidden...
            SetButtonText(btnMnu, hidMenu.Value.Split('|')[0]);
            SetButtonText(btnSplit, hidSplit.Value.Split('|')[0]);

            btnMnu.Value = hidMenu.Value.Split('|')[1];
            btnSplit.Value = hidSplit.Value.Split('|')[1];
        }
    }
}
